package com.jintoufs.domain.common;

import java.util.HashMap;
import java.util.Map;
import com.alibaba.fastjson.JSON;

/**
 * { <br>
 * 1:{"id":1,"name":"1xxx"},<br>
 * 2:{<br>
 * "id":2,<br>
 * "name":"2xxx",<br>
 * "additionalParameters":{<br>
 * "children":{<br>
 * 3:{"id":3,"name":"3xxx"}<br>
 * }<br>
 * }<br>
 * }<br>
 * }
 * 
 * @author guobing
 *         Date: 2014-7-15
 */
/**
 * Ace Tree基础类
 * 
 * @author fuhuo.zhang
 * Date:2015-3-26
 */
public class AceBaseTree<T> {
    
    /** 为前台tree json中固定字段 */
    public final static String CHILDREN = "children";
    
    /** 为前台tree json中固定字段 */
    public final static String FOLDER = "folder";
    
    /** 为前台tree json中固定字段 */
    public final static String ITEM = "item";
    
    protected Integer id;
    
    protected String name;
    
    protected String type;
    
    protected String code;
    
    public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	protected Map<String, Map<String, T>> additionalParameters;
    
    public AceBaseTree() {
        additionalParameters = new HashMap<String, Map<String, T>>();
        Map<String, T> values = new HashMap<String, T>();
        additionalParameters.put(CHILDREN, values);
    }
    
    public Integer getId() {
        return id;
    }
    
    public void setId(Integer id) {
        this.id = id;
    }
    
    public String getName() {
        return name;
    }
    
    public void setName(String name) {
        this.name = name;
    }
    
    public String getType() {
        return type;
    }
    
    public void setType(String type) {
        this.type = type;
    }
    
    public Map<String, Map<String, T>> getAdditionalParameters() {
        return additionalParameters;
    }
    
    public void setAdditionalParameters(Map<String, Map<String, T>> additionalParameters) {
        this.additionalParameters = additionalParameters;
    }
    
    public void setAdditionalParameters(String kid, T value) {
        additionalParameters.get(CHILDREN).put(kid, value);
    }
    
    /**
     * 把树转化成json
     * 
     * @return
     */
    public String toValueJsonString() {
        if (additionalParameters == null) {
            return "";
        }
        return JSON.toJSONString(additionalParameters.get(CHILDREN));
    }
    
}
